<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2048游戏</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: 'Arial', sans-serif;
            background-color: #faf8ef;
            color: #776e65;
        }
        .game-container {
            max-width: 500px;
            margin: 20px auto;
            padding: 20px;
        }
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        .title {
            font-size: 48px;
            font-weight: bold;
            color: #776e65;
        }
        .scores-container {
            display: flex;
            gap: 10px;
        }
        .score-box {
            background: #bbada0;
            padding: 10px 20px;
            border-radius: 6px;
            text-align: center;
        }
        .score-title {
            color: #eee4da;
            font-size: 14px;
            text-transform: uppercase;
        }
        .score-number {
            color: white;
            font-size: 24px;
            font-weight: bold;
        }
        .grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 12px;
            background-color: #bbada0;
            padding: 12px;
            border-radius: 8px;
        }
        .cell {
            aspect-ratio: 1;
            background-color: #cdc1b4;
            border-radius: 6px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 32px;
            font-weight: bold;
            transition: all 0.15s ease;
        }
        .cell[data-value="2"] {
            background-color: #eee4da;
            color: #776e65;
        }
        .cell[data-value="4"] {
            background-color: #ede0c8;
            color: #776e65;
        }
        .cell[data-value="8"] {
            background-color: #f2b179;
            color: #f9f6f2;
        }
        .cell[data-value="16"] {
            background-color: #f59563;
            color: #f9f6f2;
        }
        .cell[data-value="32"] {
            background-color: #f67c5f;
            color: #f9f6f2;
        }
        .cell[data-value="64"] {
            background-color: #f65e3b;
            color: #f9f6f2;
        }
        .cell[data-value="128"] {
            background-color: #edcf72;
            color: #f9f6f2;
        }
        .cell[data-value="256"] {
            background-color: #edcc61;
            color: #f9f6f2;
        }
        .cell[data-value="512"] {
            background-color: #edc850;
            color: #f9f6f2;
        }
        .cell[data-value="1024"] {
            background-color: #edc53f;
            color: #f9f6f2;
        }
        .cell[data-value="2048"] {
            background-color: #edc22e;
            color: #f9f6f2;
        
            padding: 12px;
            border-radius: 8px;
            position: relative;
        }
        .cell {
            aspect-ratio: 1;
            background-color: rgba(238, 228, 218, 0.35);
            border-radius: 6px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 28px;
            font-weight: bold;
            color: #776e65;
            transition: all 0.15s ease;
            position: relative;
        }
        .cell[data-value="2"] { background-color: #eee4da; }
        .cell[data-value="4"] { background-color: #ede0c8; }
        .cell[data-value="8"] { background-color: #f2b179; color: #f9f6f2; }
        .cell[data-value="16"] { background-color: #f59563; color: #f9f6f2; }
        .cell[data-value="32"] { background-color: #f67c5f; color: #f9f6f2; }
        .cell[data-value="64"] { background-color: #f65e3b; color: #f9f6f2; }
        .cell[data-value="128"] { background-color: #edcf72; color: #f9f6f2; font-size: 24px; }
        .cell[data-value="256"] { background-color: #edcc61; color: #f9f6f2; font-size: 24px; }
        .cell[data-value="512"] { background-color: #edc850; color: #f9f6f2; font-size: 24px; }
        .cell[data-value="1024"] { background-color: #edc53f; color: #f9f6f2; font-size: 20px; }
        .cell[data-value="2048"] { background-color: #edc22e; color: #f9f6f2; font-size: 20px; }
        .controls {
            margin-top: 20px;
            display: flex;
            justify-content: center;
            gap: 10px;
        }
        .btn {
            padding: 10px 20px;
            background-color: #8f7a66;
            color: white;
            border: none;
            border-radius: 6px;
            font-weight: bold;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .btn:hover {
            background-color: #776e65;
        }
        @media (max-width: 520px) {
            .game-container {
                padding: 10px;
                margin: 10px;
            }
            .title {
                font-size: 36px;
            }
            .cell {
                font-size: 24px;
            }
            .cell[data-value="128"],
            .cell[data-value="256"],
            .cell[data-value="512"] {
                font-size: 20px;
            }
            .cell[data-value="1024"],
            .cell[data-value="2048"] {
                font-size: 16px;
            }
        }
    </style>
</head>
<body>
    <div class="game-container">
        <div class="header">
            <h1 class="title">2048</h1>
            <div class="scores-container">
                <div class="score-box">
                    <div class="score-title">分数</div>
                    <div class="score-number" id="score">0</div>
                </div>
                <div class="score-box">
                    <div class="score-title">最高分</div>
                    <div class="score-number" id="best-score">0</div>
                </div>
                <div class="score-box">
                    <div class="score-title">剩余时间</div>
                    <div class="score-number" id="timer">{{ remaining_time }}</div>
                </div>
            </div>
        </div>
        <div class="grid" id="grid"></div>
        <div class="controls">
            <button class="btn" id="new-game">新游戏</button>
        </div>
    </div>
    <script>
    const INIT_SESSION_ID = '{{ session_id }}';
    const API_ENDPOINTS = {
        new_game: '{{ url_for('new_game') }}',
        move: '{{ url_for('move') }}'
    };
</script>
<script src="{{ url_for('static', filename='game.js') }}"></script>
</body>
</html>